using System.Collections.Generic;
using Demo.Models;
using NHibernate.Burrow.AppBlock.DAOBases;
using NHibernate.Criterion;

namespace Demo.Domain.NHibernate
{
	public class Repository<T> : GenericDAO<T>, IRepository<T> where T : IdentifiableEntity
	{
		#region IRepository<T> Members

		/// <summary>
		/// Find an entity by unique identifier.
		/// </summary>
		public T Find(int id)
		{
			return Session.CreateCriteria(typeof (T)).Add(Restrictions.Eq(Property.ForName("Id"), id)).UniqueResult<T>();
		}

		/// <summary>
		/// Save the entity on next flush of the unit of work.
		/// </summary>
		public new void Save(T entity)
		{
			base.Save(entity);
		}

		/// <summary>
		/// Finds all entities in the repository.
		/// </summary>
		public new IEnumerable<T> FindAll()
		{
			return base.FindAll();
		}

		#endregion
	}
}